#!/bin/bash
flink=/opt/module/flink-yarn/bin/flink
app_jar=/opt/gmall0521/gmall-realtime-1.0-SNAPSHOT.jar


# 数组, 获取到所有正在运行的app
runnings=`$flink list 2>/dev/null | awk '/RUNNING/{ print $(NF-1)}'`
# 定义数组
apps=(
com.atguigu.gmall.realtime.app.dwd.DwdLogApp
)

for app in ${apps[*]} ; do
    app_name=`echo $app | awk -F . '{print $NF}'`
    # app_name是否存在于runnings中
    if [[ ${runnings[@]} =~ $app_name ]]; then
        echo "$app_name 已经启动, 不需要重新启动...."
    else
        # 如果不存在
        echo "$app_name 开始启动...."
        $flink run -d -c $app $app_jar
    fi
done


